//
//  UIButton+Extension.swift
//  PGWeibo
//
//  Created by Apple on 15/11/5.
//  Copyright © 2015年 Apple. All rights reserved.
//

import UIKit


extension UIButton {
    convenience init(iconImage: String?, BackImage: String?, title: String?, textColor: UIColor = UIColor.darkGrayColor(), textSize: CGFloat = 14) {
        self.init()
        setImage(UIImage(named: iconImage ?? "") ?? nil, forState: .Normal)
        setImage(UIImage(named: iconImage ?? "" + "_highlighted") ?? nil, forState: .Highlighted)
        setBackgroundImage(UIImage(named: BackImage ?? "") ?? nil, forState: .Normal)
        setBackgroundImage(UIImage(named: "\(BackImage) + _highlighted") ?? nil, forState: .Highlighted)
        setTitle(title, forState: .Normal)
        setTitleColor(textColor, forState: .Normal)
        titleLabel?.font = UIFont.systemFontOfSize(textSize)
        sizeToFit()
    }
    convenience init(iconImage: String?, title: String?, textColor: UIColor = UIColor.darkGrayColor(), textSize: CGFloat = 14) {
        self.init()
        setImage(UIImage(named: iconImage ?? "") ?? nil, forState: .Normal)
        setImage(UIImage(named: iconImage ?? "" + "_highlighted") ?? nil, forState: .Highlighted)
        setTitle(title, forState: .Normal)
        setTitleColor(textColor, forState: .Normal)
        titleLabel?.font = UIFont.systemFontOfSize(textSize)
        sizeToFit()
    }
    convenience init(BackImage: String?, title: String?, textColor: UIColor = UIColor.darkGrayColor(), textSize: CGFloat = 14) {
        self.init()
        setBackgroundImage(UIImage(named: BackImage ?? "") ?? nil, forState: .Normal)
        setBackgroundImage(UIImage(named: "\(BackImage) + _highlighted") ?? nil, forState: .Highlighted)
        setTitle(title, forState: .Normal)
        setTitleColor(textColor, forState: .Normal)
        titleLabel?.font = UIFont.systemFontOfSize(textSize)
        sizeToFit()
    }
}
